home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
util
/
cdity
/
ModeProSrc.lha
/
Daemon
/
MPMain.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-17
|
22KB
|
696 lines
#define NO_LOCKPUBSCREENLIST
#include "MP.h"
#include <clib/extras/exec_protos.h>
#include <clib/alib_protos.h>
#include <extras/libs.h>
#include <utility/hooks.h>
#include <intuition/sghooks.h>
#include "patchdata.h"
#include <proto/locale.h>
#include <debug.h>
#include <extras/macros/exec.h>
long __stack = 4096;
LONG InPatch=0;
UBYTE EnvFile[] ="ENV:ModePro.pref",
EnvArcFile[]="ENVARC:ModePro.pref";
extern UBYTE Version[];
extern UBYTE ModePro[];
extern LONG SemVersion,
SemRevision;
extern struct List BackdropList;
extern struct SignalSemaphore LockPubSem;
#define NO_WIN_PATCH
BYTE PublicSignal;
struct Process *MPTask;
struct Screen ASM *(*OldOpenScreen)(REG __a0 struct NewScreen *,
REG __a6 struct IntuitionBase *);
struct Screen ASM *(*OldOpenScreenTagList)(REG __a0 struct ExtNewScreen *ns,
REG __a1 struct TagItem *taglist,
REG __a6 struct IntuitionBase * );
LONG ASM (*OldCloseScreen)(REG __a0 struct Screen *,
REG __a6 struct IntuitionBase *);
struct Window ASM *(*OldOpenWindow)(REG __a0 struct NewWindow *nw,
REG __a6 struct IntuitionBase *lib);
struct Window ASM *(*OldOpenWindowTagList)(REG __a0 struct NewWindow *nw,
REG __a1 struct TagItem *tags,
REG __a6 struct IntuitionBase *lib);
BOOL ASM *(*OldLayoutMenusA)(REG __a0 struct Menu *fm,
REG __a1 APTR vi,
REG __a2 struct TagItem *tags,
REG __a6 struct Library *lib);
LONG ASM *(*OldCloseWorkBench)(REG __a6 struct IntuitionBase *lib);
struct Screen * __asm (*OldLockPubScreen)(register __a0 UBYTE *Name,
register __a6 struct Library *);
void __asm (*OldUnlockPubScreen)(register __a0 UBYTE *Name,
register __a1 struct Screeen *,
register __a6 struct Library *);
struct List * __asm (*OldLockPubScreenList)(register __a6 struct Library *);
void __asm (*OldUnlockPubScreenList)(register __a6 struct Library *);
BOOL V39;
ULONG Deinstall=FALSE;
struct NewBroker NewBroker=
{
NB_VERSION,
"ModePro",
ModePro,
0,
NBU_UNIQUE | NBU_NOTIFY,
COF_SHOW_HIDE,
0,0,0
};
UWORD NumDriPens;
/*
UWORD defaultpens[]=
{
0,1,1,2,1,3,1,0,2,1,2,1
};
*/
//void asm _PROLOG(register __a0 const char *where);
//void asm _EPILOG(register __a0 const char *where);
//#define _EPILOG _MYEPILOG
//#define _PROLOG _MYPROLOG
struct TextAttr Topaz8 = { "topaz.font",8,0,0};
struct MsgPort *BrokerPort,
*CatchPort,
*ReplyPort;
struct Message *ms;
#include <proto/cybergraphics.h>
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct LocaleBase *LocaleBase;
struct Library *AslBase,
*CxBase,
*CyberGfxBase,
*DiskfontBase,
//*GadToolsBase,
*IconBase,
*IFFParseBase,
*LayersBase,
*UtilityBase,
*DataTypesBase;
struct Libs MP_Libs[]=
{
(APTR *)&AslBase, "asl.library", 38,0,
(APTR *)&CxBase, "commodities.library", 36,0,
(APTR *)&CyberGfxBase, "cybergraphics.library",39,OLF_OPTIONAL,
(APTR *)&DataTypesBase,"datatypes.library" ,39,OLF_OPTIONAL,
(APTR *)&DiskfontBase, "diskfont.library", 36,0,
// (APTR *)&GadToolsBase, "gadtools.library", 36,0,
(APTR *)&GfxBase, "graphics.library", 36,0,
(APTR *)&IconBase, "icon.library", 36,0,
(APTR *)&IFFParseBase, "iffparse.library", 36,0,
(APTR *)&IntuitionBase,"intuition.library", 36,0,
(APTR *)&LayersBase, "layers.library", 36,0,
(APTR *)&UtilityBase, "utility.library", 36,0,
0,0,0
};
CxObj *Broker;
CxMsg *cxmsg;
ULONG cxsig;
ULONG sigrcvd;
/*** Tooltypes ***/
UBYTE *Hotkey="lamiga p",
Popup=TRUE;
BYTE Priority=0;
//UBYTE *UserFontName=0;
//LONG UserFontSize=8;
STRPTR PrefsPath;
struct Catalog *Catalog;
struct MPSem *MPSem;
void main(int argc, char **argv)
{
ULONG l;
/*
DataTypesBase=OpenLibrary("datatypes.library",39);
*/
if(LocaleBase=(struct LocaleBase *)OpenLibrary("locale.library",38))
Catalog=OpenCatalog(NULL,(STRPTR)"modepro.catalog", TAG_DONE);
else
Catalog=NULL;
InitStrings();
if(ex_OpenLibs(argc,// (4.63.2) (09/17/00)
"ModePro",
GetString(MSG_REQ_COULDNT_OPEN_LIBS),
GetString(MSG_REQ_NAME_VER_FMT),
GetString(MSG_REQ_OK),
MP_Libs))
{
if(MPSem=AllocVec(sizeof(struct MPSem),MEMF_PUBLIC|MEMF_CLEAR))
{
NewList(&MPSem->ForcedEditPort.mp_MsgList);
NewList(&BackdropList);
MPSem->ForcedEditPort.mp_Flags=PA_IGNORE;
NewBroker.nb_Descr=GetString(MSG_COMMODITY_TITLE);
if(((struct Library *)IntuitionBase)->lib_Version>38)
{
NumDriPens=12;
V39=TRUE;
}
else
{
NumDriPens=9;
V39=FALSE;
}
if(GetArgs(argc,argv))
{
{
struct SignalSemaphore *sem;
sem=&MPSem->SharedSem;
for(l=0;l<SEMAPHORES;l++)
InitSemaphore(&sem[l]);
}
InitSemaphore(&LockPubSem);
MPSem->SharedSem.ss_Link.ln_Name =(UBYTE *)"ModePro";
MPSem->SharedSem.ss_Link.ln_Pri =0;
MPSem->Enabled =TRUE;
MPSem->Version =SemVersion;
MPSem->Revision=SemRevision;
MPSem->HotKey =Hotkey;
MPSem->FirstPrefsOpen=1;
/*
if(ps=LockPubScreen(NULL))
{
di=GetScreenDrawInfo(ps);
for(l=0;l<di->dri_NumPens && l<NumDriPens;l++)
defaultpens[l]=di->dri_Pens[l];
FreeScreenDrawInfo(ps,di);
UnlockPubScreen(NULL,ps);
}
*/
if(BrokerPort=CreateMsgPort())
{
NewBroker.nb_Pri=Priority;
NewBroker.nb_Port=BrokerPort;
if(Broker=CxBroker(&NewBroker,NULL))
{
AddHotKey(Broker,BrokerPort,Hotkey,EVT_HOTKEY);
if(CatchPort=CreateMsgPort())
{
if(MPSem->DaemonPort=CreateMsgPort())
{
if(ReplyPort=CreateMsgPort())
{
if((PublicSignal=AllocSignal(-1))>=0)
{
MPTask=(struct Process *)FindTask(0);
cxsig=1L<<BrokerPort->mp_SigBit;
ActivateCxObj(Broker,1);
NewList(&MPSem->OpenList);
for(l=0;l<NUM_LISTS;l++)
NewList(&MPSem->PromotionList[l]);
if(!DaemonLoadFile(EnvFile))
DaemonLoadFile(EnvArcFile);
LoadPalettePrefs();
//#include <pragmas/intuition_pragmas.h>
Forbid();
OldCloseScreen =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x42) ,(FUNCCAST)NewCloseScreen);
OldOpenScreenTagList =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)NewOpenScreenTagList);
OldOpenScreen =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0xc6) ,(FUNCCAST)NewOpenScreen);
OldLockPubScreen =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x1fe),(FUNCCAST)NewLockPubScreen);
OldUnlockPubScreen =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-516, (FUNCCAST)NewUnlockPubScreen);
#ifndef NO_LOCKPUBSCREENLIST
OldLockPubScreenList =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x20a),(FUNCCAST)NewLockPubScreenList);
OldUnlockPubScreenList=(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x210),(FUNCCAST)NewUnlockPubScreenList);
#endif
OldCloseWorkBench =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x4e) ,(FUNCCAST)NewCloseWorkBench);
OldLayoutMenusA =(FUNCCAST)SetFunction((struct Library *)GadToolsBase ,-(0x42) ,(FUNCCAST)NewLayoutMenusA);
OldOpenWindowTagList =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)NewOpenWindowTagList);
OldOpenWindow =(FUNCCAST)SetFunction((struct Library *)IntuitionBase,-(0xcc) ,(FUNCCAST)NewOpenWindow);
Permit();
AddSemaphore((struct SignalSemaphore *)MPSem);
ProcessInput();
RemSemaphore((struct SignalSemaphore *)MPSem);
ObtainSemaphore(&MPSem->ListSem);
ReleaseSemaphore(&MPSem->ListSem);
ObtainSemaphore(&MPSem->PrefsSem);
ReleaseSemaphore(&MPSem->PrefsSem);
ProcessMPMessages();
{
struct MPMessage *mpm;
while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
FreeVec(mpm);
}
FreeAllDefLists(MPSem->PromotionList);
FreeSignal(PublicSignal);
}
DeleteMsgPort(ReplyPort);
}
DeleteMsgPort(MPSem->DaemonPort);
}
DeleteMsgPort(CatchPort);
}
DeleteCxObjAll(Broker);
while(cxmsg=(CxMsg *)GetMsg(BrokerPort))
ReplyMsg((struct Message *)cxmsg);
}/* endif CxBroker() */
DeleteMsgPort(BrokerPort);
}// endif CreateMsgPort(BrokerPort)
// ArgArrayDone();
CleanupArgs(argc);
}// endif GetArgs()
FreeVec(MPSem);
}
ex_CloseLibs(MP_Libs);// (4.63.1) (09/17/00)
}
if(LocaleBase)
{
CloseCatalog(Catalog);
CloseLibrary((struct Library *)LocaleBase);
}
}
void ProcessInput(void)
{
struct DefaultNode *catdnode;
ULONG replysig,portsig,catchsig,signal,msgtype,pubsig,allsigs,daemonsig;
LONG msgid;
daemonsig = 1 << MPSem->DaemonPort->mp_SigBit;
catchsig = 1 << CatchPort->mp_SigBit;
portsig = 1 << BrokerPort->mp_SigBit;
pubsig = 1 << PublicSignal;
replysig = 1 << ReplyPort->mp_SigBit;
allsigs=daemonsig | replysig | pubsig | catchsig | portsig | SIGBREAKF_CTRL_C;
if(Popup)
ShowGUI();
while (!Deinstall)
{
signal=Wait (allsigs);
if(SIGBREAKF_CTRL_C & signal)
CheckToQuit();
if(daemonsig & signal)
ProcessMPMessages();
if(replysig & signal)
{
struct MPMessage *mpm;
while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
FreeVec(mpm);
}
if(pubsig & signal)
{
SetSignal(0,pubsig);
ClosePubScreens();
}
if(catchsig & signal)
{
while(catdnode=(struct DefaultNode *)GetMsg(CatchPort))
{
AddDNode(catdnode->Type,catdnode);
}
// if(MPSem->CatchPopup)
// ShowGUI();
}
if(portsig & signal)
{
while(cxmsg=(CxMsg *)GetMsg(BrokerPort))
{
msgid=CxMsgID(cxmsg);
msgtype=CxMsgType(cxmsg);
ReplyMsg((struct Message *)cxmsg);
switch(msgtype)
{
case CXM_IEVENT:
switch(msgid)
{
case EVT_HOTKEY:
ShowGUI();
break;
default:
{
struct OpenNode *on;
// This was ListSem... why?
ObtainSemaphoreShared(&MPSem->OpenListSem);
on=(struct OpenNode *)MPSem->OpenList.lh_Head;
while(on->on_Node.ln_Succ)
{
if(on=(struct OpenNode *)msgid)
{
ScreenToFront(on->Screen);
ActivateWindow(on->Screen->FirstWindow);
RemoveCxObj(on->Cx);
AttachCxObj(Broker,on->Cx);
/*
DeleteCxObjAll(on->Cx);
on->Cx=AddHotKey(Broker,BrokerPort,on->HotKey,(ULONG)on);
*/
break;
}
on=(struct OpenNode *)on->on_Node.ln_Succ;
}
ReleaseSemaphore(&MPSem->OpenListSem);
}
}
break;
case CXM_COMMAND:
switch(msgid)
{
case CXCMD_DISABLE:
MPSem->Enabled=FALSE;
ActivateCxObj(Broker,0);
SendPrefsMsg(MP_REFRESH,0,0);
break;
case CXCMD_ENABLE:
MPSem->Enabled=TRUE;
ActivateCxObj(Broker,1);
SendPrefsMsg(MP_REFRESH,0,0);
break;
case CXCMD_KILL:
CheckToQuit();
break;
case CXCMD_UNIQUE:
case CXCMD_APPEAR:
ShowGUI();
break;
case CXCMD_DISAPPEAR:
HideGUI();
break;
}
break;
}
}
}
}
HideGUI();
}
void ProcessMPMessages(void)
{
struct MPMessage *mpm;
while(mpm=(struct MPMessage *)GetMsg(MPSem->DaemonPort))
{
DEBUG_CODE(DKP("DaemonMsg ReplyPort %8lx Command %ld Code %ld Data %8lx\n",((struct Message *)mpm)->mn_ReplyPort, mpm->Command,mpm->Code,mpm->Data););
switch(mpm->Command)
{
case MP_QUIT:
CheckToQuit();
break;
case MP_SHOWGUI:
mpm->Code=ShowGUI();
break;
case MP_SCREENOPENED:
{
struct OpenNode *on;
on=(struct OpenNode *)mpm->Data;
ReplyMsg((struct Message *)mpm);
mpm=0;
AddBackdrop(on->Screen,on->DN);
}
break;
case MP_SCREENCLOSING:
{
struct OpenNode *on;
on=(struct OpenNode *)mpm->Data;
RemoveBackdrop(on->Screen);
}
break;
case MP_PUBSCREEN:
{
}
break;
/*
case MP_NEWNODE:
AddDNode(mpm->Code,mpm->Data);
break;
case MP_REMNODE:
RemDNode(mpm->Data);
break;
*/
}
if(mpm)
ReplyMsg((struct Message *)mpm);
}
}
void CheckToQuit(void)
{
APTR CheckCloseScreen,
CheckOpenScreen,
CheckOpenScreenTagList,
CheckOpenWindow,
CheckOpenWindowTagList,
CheckCloseWorkBench,
CheckLayoutMenusA,
CheckLockPubScreen,
CheckUnlockPubScreen;
#ifndef NO_LOCKPUBSCREENLIST
APTR CheckLockPubScreenList,
CheckUnlockPubScreenList;
#endif
BOOL patchedover=FALSE,
screensopen=FALSE;
ULONG len;
UBYTE *warning=0;
UBYTE *warn;
ObtainSemaphoreShared(&MPSem->ListSem);
ObtainSemaphore(&MPSem->OpenListSem);
Forbid();
if(!Deinstall && !InPatch)
{
if(IsListEmpty(&MPSem->OpenList))
{
/**** check LVOs and make sure their mine ****/
/**** get LVOs,so put mine in thier, and get the result ****/
CheckCloseScreen =SetFunction((struct Library *)IntuitionBase,-(0x42), (FUNCCAST)OldCloseScreen);
CheckOpenScreenTagList =SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)OldOpenScreenTagList);
CheckOpenScreen =SetFunction((struct Library *)IntuitionBase,-(0xc6), (FUNCCAST)OldOpenScreen);
CheckCloseWorkBench =SetFunction((struct Library *)IntuitionBase,-(0x4e) ,(FUNCCAST)OldCloseWorkBench);
CheckLockPubScreen =SetFunction((struct Library *)IntuitionBase,-(0x1fe),(FUNCCAST)OldLockPubScreen);
CheckUnlockPubScreen =SetFunction((struct Library *)IntuitionBase,-516, (FUNCCAST)OldUnlockPubScreen);
#ifndef NO_LOCKPUBSCREENLIST
CheckLockPubScreenList =SetFunction((struct Library *)IntuitionBase,-(0x20a),(FUNCCAST)OldLockPubScreenList);
CheckUnlockPubScreenList=SetFunction((struct Library *)IntuitionBase,-(0x210),(FUNCCAST)OldUnlockPubScreenList);
#endif
CheckLayoutMenusA =SetFunction((struct Library *)GadToolsBase ,-(0x42), (FUNCCAST)OldLayoutMenusA);
CheckOpenWindowTagList =SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)OldOpenWindowTagList);
CheckOpenWindow =SetFunction((struct Library *)IntuitionBase,-(0xcc), (FUNCCAST)OldOpenWindow);
/**** now restore the LVOs to whatever they were ***/
if((APTR)CheckCloseScreen != (APTR)NewCloseScreen ||
(APTR)CheckOpenScreenTagList != (APTR)NewOpenScreenTagList ||
(APTR)CheckOpenScreen != (APTR)NewOpenScreen ||
(APTR)CheckCloseWorkBench != (APTR)NewCloseWorkBench ||
(APTR)CheckLockPubScreen != (APTR)NewLockPubScreen ||
(APTR)CheckUnlockPubScreen != (APTR)NewUnlockPubScreen ||
#ifndef NO_LOCKPUBSCREENLIST
(APTR)CheckLockPubScreenList != (APTR)NewLockPubScreenList ||
(APTR)CheckUnlockPubScreenList != (APTR)NewUnlockPubScreenList ||
#endif
(APTR)CheckLayoutMenusA != (APTR)NewLayoutMenusA ||
(APTR)CheckOpenWindowTagList != (APTR)NewOpenWindowTagList ||
(APTR)CheckOpenWindow != (APTR)NewOpenWindow)
{
SetFunction((struct Library *)IntuitionBase,-(0x42), (FUNCCAST)CheckCloseScreen);
SetFunction((struct Library *)IntuitionBase,-(0x264),(FUNCCAST)CheckOpenScreenTagList);
SetFunction((struct Library *)IntuitionBase,-(0xc6) ,(FUNCCAST)CheckOpenScreen);
SetFunction((struct Library *)IntuitionBase,-(0x4e) ,(FUNCCAST)CheckCloseWorkBench);
SetFunction((struct Library *)IntuitionBase,-(0x1fe),(FUNCCAST)CheckLockPubScreen);
SetFunction((struct Library *)IntuitionBase,-516, (FUNCCAST)CheckUnlockPubScreen);
#ifndef NO_LOCKPUBSCREENLIST
SetFunction((struct Library *)IntuitionBase,-(0x20a),(FUNCCAST)CheckLockPubScreenList);
SetFunction((struct Library *)IntuitionBase,-(0x210),(FUNCCAST)CheckUnlockPubScreenList);
#endif
SetFunction((struct Library *)GadToolsBase ,-(0x42) ,(FUNCCAST)CheckLayoutMenusA);
SetFunction((struct Library *)IntuitionBase,-(0x25e),(FUNCCAST)CheckOpenWindowTagList);
SetFunction((struct Library *)IntuitionBase,-(0xcc) ,(FUNCCAST)CheckOpenWindow);
patchedover=TRUE;
}
else
{
Deinstall=TRUE;
SendPrefsMsg(MP_QUIT,0,0);
}
}
else
{
struct OpenNode *on;
warn=GetString(MSG_REQ_CANT_QUIT_SCREENS);
len=strlen(warn);
on=(struct OpenNode *)MPSem->OpenList.lh_Head;
while(on->on_Node.ln_Succ)
{
len+=strlen(on->Screen->Title)+4;
on=(struct OpenNode *)on->on_Node.ln_Succ;
}
if(warning=AllocVec(len,MEMF_PUBLIC|MEMF_CLEAR|MEMF_NO_EXPUNGE))
{
strcpy(warning,warn);
on=(struct OpenNode *)MPSem->OpenList.lh_Head;
while(on->on_Node.ln_Succ)
{
strcat(warning,"\n ");
strcat(warning,on->Screen->Title);
on=(struct OpenNode *)on->on_Node.ln_Succ;
}
screensopen=TRUE;
}
}
ReleaseSemaphore(&MPSem->OpenListSem);
ReleaseSemaphore(&MPSem->ListSem);
Permit();
if(patchedover)
EZReq(0,0,ModePro,GetString(MSG_REQ_CANT_QUIT_PATCHED_OVER),GetString(MSG_REQ_OK),0);
if(screensopen && warning)
{
EZReq(0,0,ModePro,warning,GetString(MSG_REQ_OK),0);
FreeVec(warning);
}
}
}
LONG SendPrefsMsg(ULONG Command, ULONG Code, APTR Data)
{
LONG rv=-1;
struct MPMessage *mpm,*rm;
struct MsgPort *mp;
ObtainSemaphore(&MPSem->PortSem);
if(MPSem->PrefsPort)
{
if(mp=CreateMsgPort())
{
rv=0;
if(mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
{
mpm->Command=Command;
mpm->Code=Code;
mpm->Data=Data;
mpm->mp_Message.mn_ReplyPort=mp;
PutMsg(MPSem->PrefsPort,(struct Message *)mpm);
rm=0;
ReleaseSemaphore(&MPSem->PortSem);
while(rm!=mpm)
{
WaitPort(mp);
rm=(struct MPMessage *)GetMsg(mp);
}
ObtainSemaphore(&MPSem->PortSem);
rv=1;
}
DeleteMsgPort(mp);
}
}
ReleaseSemaphore(&MPSem->PortSem);
return(rv);
}
BOOL DaemonLoadFile(STRPTR FileName)
{
//LONG error;
BOOL rv;
// no need for protection, the lists are not public
// when this function is called.
rv=LoadFile(MPSem->PromotionList,FileName);
/*
if(error=IoErr())
{
UBYTE errstr[91];
Fault(error,GetString(MSG_REQ_LOAD_ERROR),errstr,90);
EZReq(0,0,ModePro,errstr,GetString(MSG_REQ_OK),0);
}
*/
return(rv);
}